define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/financelog/index' + location.search,
                    edit_url: 'user/financelog/edit',
                    table: 'user_finance_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('用户昵称')},
                        {field: 'type', title: __('Type'), searchList: {"score":__('Type Score'),"money":__('Type Money'),"invoice":__('Type Invoice')}, formatter: Table.api.formatter.normal},
                        {field: 'flag', title: __('Flag'), searchList: {"add":__('Flag Add'),"reduce":__('Flag Reduce')}, formatter: Table.api.formatter.normal},
                        {field: 'before', title: __('变更前'), operate:'BETWEEN'},
                        {field: 'value', title: __('值'), operate:'BETWEEN'},
                        {field: 'after', title: __('变更后'), operate:'BETWEEN'},
                        {field: 'event', title: __('变更事件'), searchList: {"pay":__('Event pay'),"groups":__('Event groups'),"groups_refund":__('Event groups_refund'),"recharge":__('Event recharge'),"withdraw":__('Event withdraw'),"refund":__('Event refund'),"sys":__('Event sys')}, formatter: Table.api.formatter.normal},
                        // {field: 'rel_id', title: __('关联表ID')},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"waitting":__('Status Waitting'),"succeed":__('Status Succeed'),"rejected":__('Status Rejected')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: function(value,row,index){
                                if(row.status == 'waitting'){
                                    return Table.api.formatter.operate.call(this, value, row, index);
                                }else{
                                    return '-';
                                }
                            },
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
